package clog

import (
	"github.com/sirupsen/logrus"
	"os"
)


var logNetwork = logrus.New()
var logDb = logrus.New()
var logLogic = logrus.New()
var logWarning = logrus.New()
var logError = logrus.New()

func InitLogger(folder string) {
	logrus.New()
	logWarning.SetLevel(logrus.WarnLevel)
	logError.SetLevel(logrus.ErrorLevel)

	logNetwork.SetLevel(logrus.DebugLevel)
	logFile, logErr := os.OpenFile(folder + "/network.log", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0666)  //os.O_APPEND追加
	if logErr != nil {
		panic("Fail to OpenFile /network.log, err : " + logErr.Error())
	} else {
		logNetwork.SetOutput(logFile)
	}

	logDb.SetLevel(logrus.DebugLevel)
	logFile, logErr = os.OpenFile(folder + "/db.log", os.O_CREATE|os.O_RDWR, 0666)  //os.O_APPEND追加
	if logErr != nil {
		panic("Fail to OpenFile /db.log, err : " + logErr.Error())
	} else {
		logDb.SetOutput(logFile)
	}

	logLogic.SetLevel(logrus.DebugLevel)
	//logLogic.SetReportCaller(true)
	//logFile, logErr = os.OpenFile(folder + "/logic.log", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0666)  //os.O_APPEND追加
	//if logErr != nil {
	//	panic("Fail to OpenFile /logic.log, err : " + logErr.Error())
	//} else {
	//	logLogic.SetOutput(logFile)
	//}

	//if *env == "dev" {
	//	logrus.SetFormatter(&logrus.TextFormatter{
	//		FullTimestamp:             true,
	//		TimestampFormat:           "2006-01-02T15:04:05.000",
	//	})
	//} else {
	//	logrus.SetFormatter(&logrus.JSONFormatter{})
	//}
}

func Logger() *logrus.Logger {
	return logLogic
}

func LogNetwork() *logrus.Logger {
	return logLogic
}
func LogDb() *logrus.Logger {
	return logLogic
}

func LogLogic() *logrus.Logger {
	return logLogic
}

func LogWarning() *logrus.Logger {
	return logWarning
}

func LogError() *logrus.Logger {
	return logError
}